package de.fhkoeln.avs.storage;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class StorageLocationCoordinator {

	private final Integer numberOfProcessors = 4;
	
	private Integer internalCount = 0;
	
	private Properties prop = new Properties();
	
	public StorageLocationCoordinator() throws FileNotFoundException, IOException{
		prop.load(new FileInputStream("VertexCrawlerAssignment.properties"));
	}
	
	public AvsPersistentVertex getVertexHavingATurn(){
		AvsPersistentVertex vertex = null;
		
		if(internalCount == 0){
			vertex = new VertexProzessor1();
			vertex.setOwner(prop.getProperty("VertexProzessor1"));
		}else if(internalCount == 1){
			vertex = new VertexProzessor2();
			vertex.setOwner(prop.getProperty("VertexProzessor2"));
		}else if(internalCount == 2){
			vertex = new VertexProzessor3();
			vertex.setOwner(prop.getProperty("VertexProzessor3"));
		}else if(internalCount == 3){
			vertex = new VertexProzessor4();
			vertex.setOwner(prop.getProperty("VertexProzessor4"));
		}else if(internalCount == 4){
			vertex = new VertexProzessor5();
			vertex.setOwner(prop.getProperty("VertexProzessor5"));
		}else if(internalCount == 5){
			vertex = new VertexProzessor6();
			vertex.setOwner(prop.getProperty("VertexProzessor6"));
		}else if(internalCount == 6){
			vertex = new VertexProzessor7();
			vertex.setOwner(prop.getProperty("VertexProzessor7"));
		}else if(internalCount == 7){
			vertex = new VertexProzessor8();
			vertex.setOwner(prop.getProperty("VertexProzessor8"));
		}else if(internalCount == 8){
			vertex = new VertexProzessor9();
			vertex.setOwner(prop.getProperty("VertexProzessor9"));
		}else if(internalCount == 9){
			vertex = new VertexProzessor10();
			vertex.setOwner(prop.getProperty("VertexProzessor10"));
		}
		
		internalCount ++;
		if(internalCount == numberOfProcessors){
			internalCount = 0;
		}	
		return vertex;
	}
}
